package com.macaline.concurrent;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

/**
 * 未来任务
 */
public class AsyncDemo {

    public static void main(String[] args) throws InterruptedException, ExecutionException {
//        CompletableFuture<Void> completableFuture = CompletableFuture.runAsync(() -> {
//            System.out.println("11111");
//        });
//
//
//        TimeUnit.SECONDS.sleep(3);
//        completableFuture.get();


        CompletableFuture<Integer> completableFuture = CompletableFuture.supplyAsync(() -> {
            System.out.println("222222");
//            int i = 1 / 0;
            return 1024;
        });


        completableFuture.whenComplete((r, e) -> {
            System.out.println("r=" + r);
            System.out.println("e=" + e);
        });

    }
}
